﻿@using WB.UI.Designer.Code
@using WB.UI.Designer.Resources


<script type="text/javascript">
    $(function () {
        var localization = {
            CreateSubFolder: "@Html.Raw(QuestionnaireController.CreateSubFolder)",
            Edit: '@Html.Raw(QuestionnaireController.Rename)',
            Delete: "@Html.Raw(QuestionnaireController.Delete)",
            DeleteConfirmation: "@Html.Raw(QuestionnaireController.DeleteFolderConfirmation)",
            NewFolderName: "@Html.Raw(QuestionnaireController.NewFolder)",
        };
        var subFoldersUrl  = "@Url.Action("GetFolders", "PublicFolders", new { area = "Admin"})";
        var rootFoldersUrl = "@Url.Action("GetRootFolders", "PublicFolders", new { area = "Admin"})";
        var addNodeUrl     = "@Url.Action("CreateFolder", "PublicFolders", new { area = "Admin"})";
        var renameNodeUrl  = "@Url.Action("RenameFolder", "PublicFolders", new { area = "Admin"})";
        var removeNodeUrl   = null;
        var assignFolderUrl = "@Url.Action("AssignFolderToQuestionnaire", "PublicFolders", new { area = "Admin"})";
        var supportRadioButton = true;
        var selectFolderCallback = function (folderId) {
            $('#assign-folder-modal-folder-id').val(folderId);
            $('#assign-folder-button').prop('disabled', folderId == null);
        };     
        window.assignFolder = function () {
            var questionnaireId = $('#assign-folder-modal-questionnaire-id').val();
            var folderId        = $('#assign-folder-modal-folder-id').val();
            window.foldersModel.postRequest(
                assignFolderUrl,
                {
                    id: folderId,
                    questionnaireId: questionnaireId
                },
                function() {
                    location.reload(); 
                });
        };

        window.foldersModel = new FoldersModel($("#folderstree"), localization, rootFoldersUrl, subFoldersUrl, addNodeUrl, renameNodeUrl, removeNodeUrl, supportRadioButton, selectFolderCallback);
    });
</script>


<div class="modal fade" id="mAssignFolder">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="@QuestionnaireController.Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">@QuestionnaireController.AssignFolder <small>@QuestionnaireController.Confirmation</small></h4>
            </div>
            <div class="modal-body">
                <p>@Html.Raw(string.Format(QuestionnaireController.AssignFolderText, "<strong id=\"assign-folder-modal-questionnaire-title\"></strong>"))</p>
                
                <div id="folderstree" class="folder-tree disableSelection">
                </div>
            </div>
            <div class="modal-footer">
                <form method="post" asp-action="AssignFolder" asp-controller="Questionnaire">
                    @Html.AntiForgeryToken()
                    <input name="folderId" id="assign-folder-modal-folder-id" type="hidden" />
                    <input name="id" id="assign-folder-modal-questionnaire-id" type="hidden" />
                    <button class="btn" data-dismiss="modal" aria-hidden="true">@QuestionnaireController.Cancel</button>
                    <button id="assign-folder-button" type="submit" class="btn btn-primary" value="@QuestionnaireController.Assign" onclick="this.disabled = true; this.value = '@QuestionnaireController.Assigning'; window.assignFolder();">@QuestionnaireController.Assign</button>
                </form>
            </div>
        </div>
    </div>
</div>
